#!/usr/bin/env python
#-*-coding:utf-8-*-

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This project is sponsored by:
#   http://www.equiposcreativos.com/

################################################################################
# META
################################################################################

__version__ = "0.2"
__license__ = "GPL3"
__author__ = "JBC"
__since__ = "0.2"
__date__ = "2010/09/05"


################################################################################
# IMPORTS
################################################################################

import re
import unicodedata 


################################################################################
# CONSTANTS
################################################################################

_RX_A = re.compile(u"á|à|ä|â|Á|À|Â|Ä", re.UNICODE)
_RX_I = re.compile(u"í|ì|ï|î|Ì|Í|Î|Ï", re.UNICODE)
_RX_U = re.compile(u"ú|ù|ü|û|Ù|Ú|Û|Ü", re.UNICODE)
_RX_E = re.compile(u"é|è|ë|ê|È|É|Ê|Ë", re.UNICODE)
_RX_O = re.compile(u"ó|ò|ô|ö|Ò|Ó|Ô|Ö", re.UNICODE)
_RX_N = re.compile(u"ñ|Ñ", re.UNICODE)

_RX_START_END_WORD = re.compile("^\W+|\W+$", re.UNICODE)


################################################################################
# FUNCTIONS
################################################################################

def normalize(text):
    text = unicode(text)
    text = text.lower()
    text = text.strip()
    text = _RX_A.sub(u"a", text)
    text = _RX_I.sub(u"i", text)
    text = _RX_U.sub(u"u", text)
    text = _RX_E.sub(u"e", text)
    text = _RX_O.sub(u"o", text)
    text = _RX_N.sub(u"n", text)
    text = _RX_START_END_WORD.sub("", text)
    text = unicodedata.normalize('NFKD', text).encode('ASCII', 'ignore')
    return text.lower()
    
    
def split_nonalpha(text):
    return 
    
